<template>
  <a-modal title='添加地址' v-if='formModal' :visible='formModal' width='600px' @cancel='handleCancel' @ok='handleSubmit'>
    <f-form ref='form' v-if='formModal' :action='api.customAddress' :form-key='this.formItem.customAddressId'>
      <f-form-item label='地址类型' name='addressType' v-if='addressType==null' type='radio' dataType='number' :data='api.customAddress.addressType' :required='true' :value.sync='formItem.addressType' />
      <f-form-item label='收货人' name='userName' :required='true' :value='formItem.userName' />
      <f-form-item label='收货地址' name='address' :value='formItem.address' />
      <f-form-item label='联系电话' name='telephone' :value='formItem.telephone' />
      <f-form-item label='备注' name='remark' :value='formItem.remark' />
    </f-form>
  </a-modal>
</template>

<script>
import api from "./js/api"

export default {
  name: "CustomAddressModal",
  components: {},
  props: {
    addressType: {
      type: Number,
      default: null
    }
  },
  data() {
    let me = this
    return {
      api: Object.assign(api, this.api),
      formModal: false,
      customId: null,
      formItem: {
        customAddressId: "",
        addressType: 1,
        userName: "",
        address: "",
        telephone: "",
        remark: ""
      }
    }
  },
  created() {
  },
  methods: {
    showModal(record) {
      this.formModal = true

      if (record) {
        this.customCode = record.customCode
        this.formItem = record
      } else {
        this.formItem = {}
      }
    },
    handleSubmit() {
      this.$refs.form.submit({ customCode: this.customCode, addressType: this.addressType }, (data) => {
        this.handleCancel()
        this.$emit("handleSuccess", data)
      })
    },
    handleCancel() {
      this.formModal = false
    }
  }
}
</script>